Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MkCommandOutput

github Show source on GitHub

Node to display the terminal output of a command.

Examples

Example: Regular

Note

Jinja

{{ ["hatch", "--help"] | MkCommandOutput }}

Note

Python

MkCommandOutput(['hatch', '--help'])
Rendered
hatch --help /bin/sh: 1: hatch: not found
Markdown
<div data-terminal>
  <span data-ty="input">hatch --help</span>
  <span data-ty>/bin/sh: 1: hatch: not found</span>
</div>
Html
<div data-terminal>
  <span data-ty="input">hatch --help</span>
  <span data-ty>/bin/sh: 1: hatch: not found</span>
</div>

DocStrings

class MkCommandOutput(mktemplate.MkTemplate)
Base classes
⋔ Inheritance diagram
graph TD
  503546122["mkcommandoutput.MkCommandOutput"]
  1289759389["mktemplate.MkTemplate"]
  3160803176["rendercache.TemplateRenderMixin"]
  2751680898["builtins.object"]
  835538629["mkcontainer.MkContainer"]
  1956333208["mkcontainer.MkContainerBase"]
  1359323199["mknode.MkNode"]
  1289759389 --> 503546122
  3160803176 --> 1289759389
  2751680898 --> 3160803176
  835538629 --> 1289759389
  1956333208 --> 835538629
  1359323199 --> 1956333208
  2751680898 --> 1359323199
NodeFile

/home/runner/work/mknodes/mknodes/src/mknodes/templatenodes/mkcommandoutput/metadata.toml

[metadata]
icon = "mdi:bash"
name = "MkCommandOutput"

[[resources.css]]
filename = "terminal.css"

[examples.regular]
condition = "{{ 'CI' | getenv }}"
title = "Regular"
jinja = """
{{ ["hatch", "--help"] | MkCommandOutput }}
"""

[output.html]
template = """
<div data-terminal>
  <span data-ty="input">{{ node.call | join(" ") }}</span>
  <span data-ty>{{ node.output }}</span>
</div>
"""

Code

mknodes.templatenodes.mkcommandoutput.MkCommandOutput

class MkCommandOutput(mktemplate.MkTemplate):
    """Node to display the terminal output of a command."""

    ICON = "material/bash"
    STATUS = "new"
    CSS = [resources.CSSFile("terminal.css")]

    def __init__(self, call: Sequence[str], **kwargs: Any) -> None:
        """Constructor.

        Args:
            call: System call to make
            kwargs: Keyword arguments passed to parent
        """
        self.call = call
        super().__init__("output/html/template", **kwargs)

    @property
    def cwd(self):
        return self.ctx.metadata.repository_path

    def _command_params(self) -> dict[str, Any]:
        cwd = self.cwd
        return dict(call=" ".join(self.call), cwd=str(cwd) if cwd else None)

    def get_input_requests(self) -> list[inputs.InputRequest]:
        return [inputs.InputRequest.create("command", **self._command_params())]

    @property
    def output(self) -> str | None:
        """Output of the command (run in the resolve phase, inputs store kind `command`)."""
        return self.ctx.inputs.get("command", **self._command_params())

Page info
Code for this page

mknodes.manual.nodes_section.create_section_for_nodes

def create_section_for_nodes(
    nav: mk.MkNav,
    klasses: Sequence[type[mk.MkNode]],
) -> mk.MkTable:
    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
    for kls in klasses:
        tpl = "classpage_custom.jinja"
        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
        nav += page
        if kls.STATUS:
            page.metadata.status = kls.STATUS
        elif kls.JS_FILES:
            page.metadata.status = "js"
        elif kls.CSS:
            page.metadata.status = "css"
        page.created_by = create_section_for_nodes
        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
        table.add_row((link, kls.__doc__, extensions))
    return table

Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                           'format': <function fence_code_format at 0x7d707a397060>,
                                                                           'name': 'mermaid'}]},
                               'pymdownx.tabbed': {},
                               'tables': {}},
          plugins=[Plugin('mkdocstrings')],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
  source_function: create_section_for_nodes
  source_line_no: 93
hide:
- toc
icon: material/bash
status: new
title: MkCommandOutput